using System.Windows;
using System.Windows.Controls;

using Synergy.Extensions;

namespace Synergy.Windows.Controls.Extensions
{
	/// <summary>
	/// Extension methods for the <see cref="Canvas"/> class.
	/// </summary>
	/// <remarks>
	///		<list type="table">
	///			<listheader><term>Version</term><description>Description</description></listheader>
	///			<item>
	///				<term>1.0</term>
	///				<description>Initial version</description>
	///			</item>
	///		</list>
	/// </remarks>
	public static class CanvasExtension
	{
		/// <summary>
		/// Gets the center point of the specified <paramref name="element"/>.
		/// </summary>
		/// <param name="canvas">The canvas.</param>
		/// <param name="element">The element.</param>
		/// <returns>The center point.</returns>
		/// <remarks>
		///		Code analysis message CA1801 (Review Unused Parameters) is being suppressed here because the 
		///		<paramref name="canvas"/> parameter is required for the extension method.
		/// </remarks>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "canvas")]
		public static Point GetCenter(this Canvas canvas, FrameworkElement element)
		{
			return GetCenter(new Point(Canvas.GetLeft(element), Canvas.GetTop(element)), new Size(element.Width, element.Height));
		}


		/// <summary>
		/// Gets the center point given the top-left element position and specified <paramref name="size"/>.
		/// </summary>
		/// <param name="topLeft">The top left.</param>
		/// <param name="size">The size.</param>
		/// <returns>The center point.</returns>
		public static Point GetCenter(Point topLeft, Size size)
		{
			return new Point(topLeft.X + (size.Width / 2), topLeft.Y + (size.Height / 2));
		}


		/// <summary>
		/// Checks the specified <see cref="point"/> to see if it falls within the client area of the specified <paramref name="element"/>.
		/// </summary>
		/// <param name="canvas">The canvas containing the element.</param>
		/// <param name="element">The element.</param>
		/// <param name="point">The point.</param>
		/// <returns><c>true</c> if the point is within the element's client area; otherwise, <c>false</c>.</returns>
		/// <remarks>
		///		Code analysis message CA1801 (Review Unused Parameters) is being suppressed here because the 
		///		<paramref name="canvas"/> parameter is required for the extension method.
		/// </remarks>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "canvas")]
		public static bool InClientArea(this Canvas canvas, FrameworkElement element, Point point)
		{
			return InClientArea(new Point(Canvas.GetLeft(element), Canvas.GetTop(element)), new Size(element.Width, element.Height), point);
		}


		/// <summary>
		/// Checks the specified <see cref="point"/> to see if it falls within the client area depicted by the specified 
		/// <paramref name="topLeft"/> point and <paramref name="size"/>.
		/// </summary>
		/// <param name="topLeft">The top left.</param>
		/// <param name="size">The size.</param>
		/// <param name="point">The point.</param>
		/// <returns><c>true</c> if the point is within the element's client area; otherwise, <c>false</c>.</returns>
		public static bool InClientArea(Point topLeft, Size size, Point point)
		{
			return (point.X.Between(topLeft.X, topLeft.X + size.Width) && point.Y.Between(topLeft.Y, topLeft.Y + size.Height));
		}
	}
}